package main

import (
	"gitee.com/konica/udptest"
	"github.com/urfave/cli/v2"
	"os"
)

func main() {
	app := &cli.App{
		Name:    "udptest",
		Version: "1.0",
		Commands: []*cli.Command{
			{
				Name:     "c",
				HelpName: "client mode",
				Action: func(c *cli.Context) error {
					var (
						serverAddr = c.String("server_addr")
						localAddr  = c.String("local_addr")
					)
					return udptest.NewClient(localAddr, serverAddr)
				},
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:    "server_addr",
						Aliases: []string{"sa"},
						Value:   "127.0.0.1:10086",
					},
					&cli.StringFlag{
						Name:    "local_addr",
						Aliases: []string{"la"},
						Value:   "0.0.0.0:54321",
					},
				},
			},
			{
				Name:     "s",
				HelpName: "server mode",
				Action: func(c *cli.Context) error {
					var (
						addr = c.String("addr")
					)
					udptest.NewServer(addr)
					return nil
				},
				Flags: []cli.Flag{
					&cli.StringFlag{
						Name:    "addr",
						Aliases: []string{"a"},
						Value:   ":10086",
					},
				},
			},
		},
	}

	app.Run(os.Args)
}
